package dao

import (
	"errors"
	"quant/backend/entity"

	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

type UserDao struct {
	// 引入公共类
	// baseService
	*BaseDao[entity.UserEntity]
}

// NewUserDao 初始化
func NewUserDao() *UserDao {
	return &UserDao{
		BaseDao: NewBaseDao[entity.UserEntity](),
	}
}

func (dao *UserDao) FindUserByUsername(ctx *gin.Context, username string) (entity.UserEntity, error) {
	var user entity.UserEntity
	user.Username = username
	has, err := dao.engine.Get(&user)
	if err != nil {
		logrus.Error(err.Error())
		return user, err
	}
	if !has {
		return user, errors.New("用户不存在")
	}
	return user, nil
}
